package com.shujia.spark.core

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.rdd.RDD

object Demo08Cartesian {
  def main(args: Array[String]): Unit = {

    /**
     * cartesian：转换算子，可以用于对两个RDD的数据进行笛卡尔积运算
     */
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName(this.getClass.getSimpleName.replace("$", ""))
    val sc = new SparkContext(conf)

    val rdd01: RDD[Int] = sc.parallelize(List(1, 2, 3, 4, 5))
    val rdd02: RDD[String] = sc.parallelize(List("4","5","6"))

    val cartesianRDD: RDD[(Int, String)] = rdd01.cartesian(rdd02)
    cartesianRDD.foreach(println)
  }

}
